package com.hucheng.seckill.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.hucheng.seckill.dto.SeckillOrderDTO;
import com.hucheng.seckill.entity.SeckillOrderDO;
import com.hucheng.seckill.mapper.SeckillOrderMapper;
import com.hucheng.seckill.service.SeckillOrderService;
import com.hucheng.seckill.vo.SeckillOrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-07-01
 * @Description: 类描述
 **/
@Component
@Service(interfaceClass = SeckillOrderService.class, retries = -1, timeout = 5000)
public class SeckillOrderServiceImpl implements SeckillOrderService {

    @Autowired
    private SeckillOrderMapper seckillOrderMapper;

    @Override
    @Transactional
    public SeckillOrderVO createSeckillOrder(Integer userId, Integer goodsId, Integer orderId) {
        SeckillOrderDO seckillOrderDO = new SeckillOrderDO();
        seckillOrderDO.setUserId(userId);
        seckillOrderDO.setOrderId(orderId);
        seckillOrderDO.setGoodsId(goodsId);

        Integer id = seckillOrderMapper.insert(seckillOrderDO);

        SeckillOrderVO seckillOrderVO = new SeckillOrderVO();
        seckillOrderVO.setSeckillOrderId(seckillOrderDO.getSeckillOrderId());
        seckillOrderVO.setUserId(userId);
        seckillOrderVO.setGoodsId(goodsId);
        return seckillOrderVO;
    }

    @Override
    public SeckillOrderVO getUserSeckillOrderByUserId(Integer userId, Integer goodsId) {
        return SeckillOrderVO.buildSeckillGoodsVO(seckillOrderMapper.getUserSeckillOrderByUserId(userId, goodsId));
    }
}
